﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace MSSQLDAL
{
    public class DBCommon
    {
        public DBCommon()
        {
        }

        public static DataTable SqlGetTable(string TransSQL)
        {
            return SqlHelper.ExecuteDataset(Conn.SqlConnStr, CommandType.Text, TransSQL).Tables[0];
        }

        public static int ExecSqlCommand(string TransSQL)
        {
            return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, TransSQL);
        }

        public static int GetNewIDForTable(string newid_key, string actual_table, string actual_field)
        {
            string SqlStr = " declare @tabcount int " +
                            " select @tabcount=count(*) from sys_newid_seed where tablename= '" + newid_key + "'" +
                            " if @tabcount=0 " +
                            "     insert into sys_newid_seed(tablename,new_id,actual_table,actual_field) values('" + newid_key + "',1,'" + actual_table + "','" + actual_field + "') " +
                            " else " +
                            "     update sys_NewId_Seed set new_id=new_id+1 where tablename= '" + newid_key + "'" +
                            " select  new_id  from sys_NewId_Seed where tablename= '" + newid_key + "'";
            return (int)SqlHelper.ExecuteScalar(Conn.SqlConnStr, CommandType.Text, SqlStr);
        }

    }
}
